using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Controls;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Input;
using System.Windows;
using CoastToCoast.Game;
using CoastToCoast.Client.Views;

namespace CoastToCoast.Client {
    public class CellView {
        private UnitView _unitView;
        public UnitView UnitView {
            get { return _unitView; }
            set { _unitView = value; }
        }

        private TerrainView _terrainView;
        public TerrainView TerrainView {
            get { return _terrainView; }
            set { _terrainView = value; }
        }

        // Rectangle that contains the cell
        private Rectangle _rectangle;
        public Rectangle Rectangle {
            get { return _rectangle; }
            set { _rectangle = value; }
        }

        public CellView(Cell cell, Rectangle rect) {
            TerrainView = ViewFactory.CreateTerrainView(cell.Terrain, this);
            Rectangle = rect;
            Brush terrainBrush = new SolidColorBrush(TerrainView.Background);
            //if (cell.Units.Count > 0) {
            if (cell.Unit != null) {
                Rectangle.Stroke = terrainBrush;
                UnitView = ViewFactory.CreateUnitView(cell.Unit, this);
                ImageBrush image = new ImageBrush();
                image.ImageSource = new Uri(UnitView.Image, UriKind.Relative);
                Rectangle.Fill = image;
            }
            else if (cell.Terrain is City) {
                Rectangle.Stroke = terrainBrush;
                ImageBrush image = new ImageBrush();
                // TODO: get rid of this hardcode?
                image.ImageSource = new Uri("city.jpg", UriKind.Relative);
                Rectangle.Fill = image;
            }
            else {
                Rectangle.Fill = terrainBrush;
            }
        }
    }
}
